package com.caiden_micheal.dynamic.form_workflow.mapper;

import com.caiden_micheal.dynamic.form_workflow.domain.FormWorkflow;
import com.caiden_micheal.dynamic.form_workflow.dto.FindFormWorkflowPageQueryDTO;
import com.caiden_micheal.dynamic.form_workflow.vo.FormWorkflowSelectDataVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface FormWorkflowMapper {
    void addFormWorkflow(FormWorkflow formWorkflow);

    void updateFormWorkflow(FormWorkflow formWorkflow);

    @Select("SELECT * FROM sys_form_workflow WHERE id=#{id}")
    FormWorkflow findById(Long id);

    void updateExplain(@Param("id") Long id, @Param("explain") String explain);

    @Select("SELECT * FROM sys_form_workflow WHERE display_name=#{displayName}")
    FormWorkflow findByDisplayName(String displayName);

    List<FormWorkflow> findFormWorkflowByCondition(FindFormWorkflowPageQueryDTO findFormWorkflowPageQueryDTO);

    Integer findFormWorkflowByConditionCount(FindFormWorkflowPageQueryDTO findFormWorkflowPageQueryDTO);

    @Delete("DELETE FROM sys_form_workflow WHERE id=#{id}")
    void remove(Long id);

    @Select("SELECT * FROM sys_form_workflow WHERE form_id=#{id}")
    List<FormWorkflow> findFormWorkflowByFormId(Long id);

    @Select("SELECT * FROM sys_form_workflow WHERE workflow_id=#{id}")
    List<FormWorkflow> findFormWorkflowByWorkflowId(Long id);

    @MapKey("id")
    Map<Long, Map<String, String>> findMapByIdList(@Param("formWorkflowIdList") List<Long> formWorkflowIdList);

    @Select("SELECT * FROM sys_form_workflow WHERE display_name LIKE CONCAT('%',#{displayName},'%') ORDER BY create_time DESC LIMIT 0,20")
    List<FormWorkflowSelectDataVO> findFormWorkflowSelectData(String displayName);
}
